<header class="header">
    <div class="headerbox">
        <!-- 顶部菜单 -->
        <div class="header-menuv3">
            <div class="width1260 menuboxv3">
                <div class="logov3"><a href="/"><img src="/image/logo.png" alt="超级游乐场" class="img-responsive"></a></div>
                <nav class="menunavv3">
                    <% if(!allMine.length){ %>
                        <a href="/singin" class="gamehelpv3"><i class="icon iconfont icon-30"></i><%= __('RecharGe') %></a>
                    <% } %>
                    <% if(allMine.length){ %>
                        <a href="/transaction/id=0&name=HPS" class="gamehelpv3"><i class="icon iconfont icon-30"></i><%= __('RecharGe') %></a>
                    <% } %>
                    <a href="https://kf1.learnsaas.com/chat/chatClient/chatbox.jsp?companyID=951120&configID=71038&jid=5076028323&s=1" 
                    target="_blank" class="gamehelpv3"><i class="icon iconfont icon-kefu"></i><%= __('onlineService') %></a>
                    <a href="https://mp.weixin.qq.com/s/YJiFu89hM_rYIlEObLbb3w" class="gamehelpv3" target="_blank"><i class="icon iconfont icon-bangzhu"></i><%= __('webhelp') %></a>
                    <% if(allMine.length){ %>
                        <div class="enterweb enterwebv3">
                                <input type="hidden" value="<%= lastFaucetTime %>" class="Thereare">
                                <input type="hidden" value="<%= allMine[0].lastFaucetTime %>" class="lastFauce">
                                <div class="myemailaddress">
                                    <div class="emailaddress emailaddressv3"> 
                                        <span v-html="uname+'(UID：'+uid+')'"></span>
                                        <i class="icon iconfont icon-sanjiaodown"></i>
                                    </div>
                                            <div class="newemailbox">
                                                <div class="userlogout">
                                                    <div class="useravatar">
                                                        <% if(userbasicinfo.avatar) { %>
                                                            <img src="<%= userbasicinfo.avatar %>" alt="用户头像" class="avataraddress">
                                                        <% }else { %>
                                                            <img src="/image/avatar.png" alt="用户头像" class="avataraddress">
                                                        <% } %>
                                                        <span class="usernickname"><%= userbasicinfo.nickname %></span>
                                                    </div>
                                                    <div class="userlogoutbtn" @click="signout"><%= __('userlogout') %></div>
                                                </div>
                                                <div class="gotogrowth">
                                                    <div class="gotogrowthlist">
                                                        <a href="/growth">
                                                            <i></i><span><%= __('gotogrowthlist1') %></span>
                                                        </a>
                                                    </div>
                                                    <div class="gotogrowthlist">
                                                        <a href="/growth?type=1">
                                                            <i></i><span><%= __('gotogrowthlist2') %></span>
                                                        </a>
                                                    </div>
                                                    <div class="gotogrowthlist">
                                                        <a href="/growth?type=2">
                                                            <i></i><span><%= __('gotogrowthlist3') %></span>
                                                        </a>
                                                    </div>
                                                    <div class="gotogrowthlist">
                                                        <a href="/growth?type=3">
                                                            <i></i><span><%= __('gotogrowthlist4') %></span>
                                                        </a>
                                                    </div>
                                                </div>
                                                <div class="usercoinarr">
                                                    <% if(allMine.length){ %>
                                                        <% allMine.forEach( (item,index) => { %>
                                                            <div class="usercoinarrlist">
                                                                <div class="usercoinarrcoin">
                                                                    <img src="/image/<%= item.coin %>.png" alt="<%= item.coin %>" class="coinicon img-responsive">
                                                                    <span class="coinname"><%= item.coin %></span>
                                                                </div>
                                                                <div class="coinbanlance"><%= item.balance %></div>
                                                            </div>
                                                        <% }) %>
                                                    <% } %>
                                                </div>
                                </div>
                            </div>
                        </div>
                    <% }else{ %>
                        <div class="singinbtnv3">
                            <a href="/singin"><%= __('Thelogin') %></a>
                            <a href="/registered"><%= __('Registered') %></a>
                        </div>
                    <% } %>
                </nav>
            </div>
        </div>
        <!-- 导航菜单 -->
        <nav class="navv3">
            <div class="width1260 routernavv3">
                <div>
                    <a href="/" class="routelinkitemv3 <%= lang%>" 
                    :class="{routeactiveitemv3:menuactiveitem=='/'}"><%= __('Home') %></a>
                </div>
                <% if(allMine.length){ %>
                    <div>
                        <a class="routelinkitemv3 <%= lang%>" 
                        @click="gotohyperdice"><%= __('hyperdice') %></a>
                    </div>
                    <div><a href="/moregame" class="routelinkitemv3 <%= lang%>" :class="{routeactiveitemv3:menuactiveitem=='/moregame'}"><%= __('AGAsiaTour') %></a></div>
                    <div><a href="/PicksPal" class="routelinkitemv3 <%= lang%>" :class="{routeactiveitemv3:menuactiveitem=='/PicksPal'}"><%= __('PicksPal') %></a></div>
                    <div><a href="/tcggame" class="routelinkitemv3 <%= lang%>" :class="{routeactiveitemv3:menuactiveitem=='/tcggame'}"><%= __('BlockLottery') %></a></div>
                <% } %>
                <% if(!allMine.length){ %>
                    <div>
                        <a href="/singin" class="routelinkitemv3 <%= lang%>"><%= __('hyperdice') %></a>
                    </div>
                    <div><a href="/singin" class="routelinkitemv3 <%= lang%>" :class="{routeactiveitemv3:menuactiveitem=='/moregame'}"><%= __('AGAsiaTour') %></a></div>
                    <div><a href="/singin" class="routelinkitemv3 <%= lang%>" :class="{routeactiveitemv3:menuactiveitem=='/PicksPal'}"><%= __('PicksPal') %></a></div>
                    <div><a href="/singin" class="routelinkitemv3 <%= lang%>" :class="{routeactiveitemv3:menuactiveitem=='/LotteryTicket'}"><%= __('BlockLottery') %></a></div>
                <% } %>
            </div>
        </nav>
    </div>
</header>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    var app = new Vue({
        el: '.header',
        data: {
            contactnum: 0,
            isshowlanguage: false,
            showText: false,
            hideText: true,
            uname:localStorage.getItem('user'),
            uid:localStorage.getItem('ID'),
            isshowemailsubmenu:false,
            mianfei: '',
            menuactiveitem:'', //当前选中菜单
            faucetnum:0
        },
        created() {
            let test =window.location.href
            let lang = this.getCookie("lang");
            if(test.indexOf("ref")!= -1){
                let ref=test.substring(test.indexOf("ref") + 4)
                window.sessionStorage.setItem('refererId',ref)      
            }
            this.menuactiveitem=location.href.slice(location.href.lastIndexOf('/'))
            if (document.getElementsByClassName('Thereare')[0] == undefined) {
                if (lang == "en_US") {
                    this.mianfei = "Free coin";
                } else if (lang == "zh_TW") {
                    this.mianfei = "免費領幣";
                } else {
                    this.mianfei = "免费领币"
                }
            } else {
                let LastTime = document.getElementsByClassName('lastFauce')[0].value
                if(LastTime==""){
                    if (lang == "en_US") {
                        this.mianfei = "Free coin";
                    } else if (lang == "zh_TW") {
                        this.mianfei = "免費領幣";
                    } else {
                        this.mianfei = "免费领币"
                    }
                }else{
                    this.FreeFaucet()
                }
            }
        },
        methods: {
            getCookie(cookiename) { //获取cookie
                var arr,
                reg = new RegExp("(^| )" + cookiename + "=([^;]*)(;|$)");
                if ((arr = document.cookie.match(reg))) {
                    return unescape(arr[2]);
                } else {
                    return null;
                }
            },
            gotohyperdice(){ //头部前去dice
                if(localStorage.getItem('ID')!=null||localStorage.getItem('ID')!=''){
                    if(this._mime("type", "application/vnd.chromium.remoting-viewer")){
                        let dialogopt={
                            zh_CN:{
                                title1:'友情提示',
                                title2:'弹出窗口若被阻拦，请在右上角或浏览器设置里允许显示弹出式窗口'
                            },
                            zh_TW:{
                                title1:'友情提示',
                                title2:'彈出窗口若被阻攔，請在右上角或瀏覽器設置裏允許顯示彈出式窗口'
                            },
                            en_US:{
                                title1:'Help',
                                title2:'If pop-ups are blocked, allow pop-ups in the upper-right corner or browser settings'
                            }
                        }
                        this.opendialog(dialogopt)
                    }
                    axios.post('/user/setredis',{}).then((res) => {
                        if(res.data.code==200){
                            if(res.data.data!='fail'){
                                let userkey=res.data.data
                                let url='http://dice.play.top/?key='
                                window.open(`${url}${userkey}`,'_self')
                            }else{
                                location.href='/singin'
                            }
                        }else{
                            location.href='/singin'
                        }
                    })
                }else{
                    location.href='/singin'
                }
            },
            contactover(index) {
                this.$refs.connectcode.style.display = "block";
                this.contactnum = index;
            },
            contactout(index) {
                this.$refs.connectcode.style.display = "none"
                this.contactnum = index;
            },
            chooselanguage(lang, defaultlang) { //选择语言
                this.isshowlanguage = false
                if (lang === defaultlang) { //默认语言
                    return
                }
                let params = {
                    lang: lang
                }
                axios.post('/user/setlanguage', params).then((res) => {
                    if (res.data.code == 200) {
                        location.reload()
                    }
                })
            },
            getCookie(cookiename) { //获取cookie
                var arr, reg = new RegExp("(^| )" + cookiename + "=([^;]*)(;|$)");
                if (arr = document.cookie.match(reg)) {
                    return unescape(arr[2]);
                } else {
                    return null;
                }
            },
            overShow () {
                this.showText = !this.showText
                this.hideText = !this.hideText
            },
            outHide () {
                this.showText = !this.showText
                this.hideText = !this.hideText
            },
            signout(){ //退出登录
                axios.post('/user/usersignout',{}).then((res) => {
                    if(res.data.code===200){
                        location.href='/'
                        localStorage.clear()
                        sessionStorage.clear()
                    }
                })
            },
            FreeFaucet() {
                let FAUCE = document.getElementsByClassName('lastFauce')[0].value ||0
                let lang = this.getCookie("lang");
                if (FAUCE) {
                    let timer = new Date().getTime()
                    let countdown = timer - FAUCE
                    // - 8 * 60 * 60 * 1000
                    let lastTime = 24 * 60 * 60 * 1000 - countdown
                    if (countdown > 24 * 60 * 60 * 1000) {
                        if (lang == "en_US") {
                            this.mianfei = "Free coin";
                        } else if (lang == "zh_TW") {
                            this.mianfei = "免費領幣";
                        } else {
                            this.mianfei = "免费领币"
                        }
                        return
                    }
                    let obj = {
                        h: null,
                        m: null,
                        s: null
                    };
                    obj.h = Math.floor(lastTime / 1000 / 60 / 60);
                    obj.m = parseInt((lastTime / 1000 / 60) % 60, 10);
                    obj.s = parseInt((lastTime / 1000) % 60, 10);
                    let timelast = setInterval(() => {
                        obj.s--
                        if (obj.s < 0) {
                            --obj.m;
                            obj.s = 59;
                        }
                        if (obj.m < 0) {
                            --obj.h;
                            obj.m = 59;
                        }
                        if (obj.h < 0) {
                            obj.s = 0;
                            obj.h = 0;
                            obj.m = 0;
                        }
                        function charLeftAll(n) {
                            if (n < 10) return "0" + n;
                            else return n;
                        }
                        this.mianfei = charLeftAll(obj.h) +
                        ":" +
                        charLeftAll(obj.m) +
                        ":" +
                        charLeftAll(obj.s)
                        if (obj.s == 0 && obj.h == 0 && obj.m == 0) {
                            if (lang == "en_US") {
                                this.mianfei = "Free coin";
                            } else if (lang == "zh_TW") {
                                this.mianfei = "免費領幣";
                            } else {
                                this.mianfei = "免费领币"
                            }
                            clearInterval(timelast)
                        }
                    }, 1000);
                    return
                }
            },
            FreeFaucetone() {
                if (this.mianfei == "免费领币" || this.mianfei == "免費領幣" || this.mianfei == "Free coin") {
                    this.faucetnum=1
                    if(this.faucetnum==1){
                        setTimeout( () => {
                            this.faucetnum=0
                        },2000)
                    }
                    axios.post("/adress/coin/faucet").then(res => {
                        if (res.data.data != undefined) {
                            let obj = {
                                h: null,
                                m: null,
                                s: null
                            };
                            obj.h =23
                            obj.m =59
                            obj.s = 60
                            let timelast = setInterval(() => {
                            obj.s--
                            if (obj.s < 0) {
                                --obj.m;
                                obj.s = 59;
                            }
                            if (obj.m < 0) {
                                --obj.h;
                                obj.m = 59;
                            }
                            if (obj.h < 0) {
                                obj.s = 0;
                                obj.h = 0;
                                obj.m = 0;
                            }
                            function charLeftAll(n) {
                                if (n < 10) return "0" + n;
                                else return n;
                            }
                            this.mianfei = charLeftAll(obj.h) +
                            ":" +
                            charLeftAll(obj.m) +
                            ":" +
                            charLeftAll(obj.s)
                            }, 1000);
                        } else {

                        }
                    });
                }else{
                    
                }
            },
            xxtea_encrypt(str, key) {
                if (str == "") {
                    return "";
                }
                var v = this.str2long(str, true);
                var k = this.str2long(key, false);
                if (k.length < 4) {
                    k.length = 4;
                }
                var n = v.length - 1;
            
                var z = v[n], y = v[0], delta = 0x9E3779B9;
                var mx, e, p, q = Math.floor(6 + 52 / (n + 1)), sum = 0;
                while (0 < q--) {
                    sum = sum + delta & 0xffffffff;
                    e = sum >>> 2 & 3;
                    for (p = 0; p < n; p++) {
                        y = v[p + 1];
                        mx = (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
                        z = v[p] = v[p] + mx & 0xffffffff;
                    }
                    y = v[0];
                    mx = (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
                    z = v[n] = v[n] + mx & 0xffffffff;
                }
                return this.long2str(v, false);
            },
            long2str (v, w) {
                var vl = v.length;
                var n = (vl - 1) << 2;
                if (w) {
                    var m = v[vl - 1];
                    if ((m < n - 3) || (m > n)) return null;
                    n = m;
                }
                for (var i = 0; i < vl; i++) {
                    v[i] = String.fromCharCode(v[i] & 0xff,
                                            v[i] >>> 8 & 0xff,
                                            v[i] >>> 16 & 0xff,
                                            v[i] >>> 24 & 0xff);
                }
                if (w) {
                    return v.join('').substring(0, n);
                }
                else {
                    return v.join('');
                }
            },
            str2long(s, w) {
                var len = s.length;
                var v = [];
                for (var i = 0; i < len; i += 4) {
                    v[i >> 2] = s.charCodeAt(i)
                            | s.charCodeAt(i + 1) << 8
                            | s.charCodeAt(i + 2) << 16
                            | s.charCodeAt(i + 3) << 24;
                }
                if (w) {
                    v[v.length] = len;
                }
                return v;
            },
            _mime(option, value) { //判断是否是360浏览器
                var mimeTypes = navigator.mimeTypes;
                for (var mt in mimeTypes) {
                    if (mimeTypes[mt][option] == value) {
                        return true;
                    }
                }
                return false;
            },
            opendialog(obj) { //打开遮罩层
                let lang = this.getCookie("lang");
                var a = '<div class="errorMessage"><div class="errorMessageTop" v-html="theuser"></div> <div class="errorMessageBottom" v-html="information"></div><img src="/image/close.png" alt="" class="closeinfo"></div>'
                document.querySelector('.header').insertAdjacentHTML('afterBegin', a)
                var b = '<div class="maskLayer"></div>'
                document.querySelector('.header').insertAdjacentHTML('afterBegin', b)
                document.getElementsByClassName("closeinfo")[0].onclick = () => {
                    var c = document.getElementsByClassName('maskLayer')[0]  //移除元素
                    var d = document.getElementsByClassName('errorMessage')[0] //移除元素
                    document.querySelector('.header').removeChild(c)
                    document.querySelector('.header').removeChild(d)
                }
                document.getElementsByClassName('errorMessageTop')[0].innerHTML = obj[lang].title1
                document.getElementsByClassName('errorMessageBottom')[0].innerHTML = obj[lang].title2
            }
        }
    })
</script>
